package com.wisdytech.common.handler;


import com.wisdytech.linkdcs.system.dao.ISysResourceDao;
import com.wisdytech.linkdcs.system.model.SysResource;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Service("resourceMatchingService")
public class ResourceMatchingService {

    @Resource
    private ISysResourceDao sysResourceDao;

    public void getResourceName(HttpServletRequest httpRequest, Model model){
        String requestURI = httpRequest.getRequestURI();
        String uri = requestURI.substring(9);
        List<SysResource> list = new ArrayList<>();
        List<SysResource> syslist = sysResourceDao.getResourceName(uri);
        for(int i = syslist.size();i>0;i--){
            list.add(syslist.get(i-1));
        }
        for(int i = 0;i<list.size();i++){
            int j = i+1;
            model.addAttribute("level"+j, list.get(i).getResName());
        }
    }

    public void getTitle(String type, Model model) {
        switch(type) {
            case "3":
                model.addAttribute("title1", "车间组态管理");
                model.addAttribute("title2", "车间组态设计");

                break;
            case "2":
                model.addAttribute("title1", "产线组态管理");
                model.addAttribute("title2", "产线组态设计");
                break;
            case "1":
                model.addAttribute("title1", "厂区组态管理");
                model.addAttribute("title2", "厂区组态设计");
                break;
        }
    }
}
